public class num387 {
    //返回字符串中第一个不重复元素的索引
    public int firstUniqChar(String s) {
        int[] freq = new int[26];
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            freq[c - 'a'] ++;//此时freq相当于哈希表，c - 'a'相当于索引,对应的值为出现的次数
        }
        int ret = -1;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if(freq[c - 'a'] == 1){
                ret = i;
                return ret;
            }
        }
        return ret;
    }
}
